package com.hr.builder;

import java.util.List;

import org.springframework.stereotype.Component;

import com.espirit.eap.manager.ModelBuilderSupport;
import com.espirit.eap.pagelayout.DetailLayout;
import com.espirit.eap.pagelayout.Element;
import com.espirit.eap.pagelayout.FlatSection;
import com.espirit.eap.pagelayout.GridSection;
import com.espirit.eap.pagelayout.Model;
import com.espirit.eap.pagelayout.TabbedSection;
import com.hr.SalaryDefine;
import com.hr.SalaryEmployeeDefine;


@Component
public class SalaryDefineBuilder extends ModelBuilderSupport {
	static final String DEPTIDS = "deptIds";
	static final String DEPARTMENT = "department";
	static final String ACCTTERM = "acctTerm";
	
	static final String MONTH_SALARY_DAYS = "monthSalaryDays";
	static final String DAY_SALARY_HOURS = "daySalaryHours";
	
	@Override
	public boolean init() {
		return super.setClass(SalaryDefine.class, "Salary Define", "薪资定义");
	}

	@Override
	public void buildFields() {
		super.buildFields();
		addModelField(DEPARTMENT, "Department", "部门");
		addModelField(DEPTIDS, "Department", "部门");
		addModelField(ACCTTERM, "Acct Term", "会计期间");
		
		addModelField(MONTH_SALARY_DAYS, "Month salary days", "月计薪天数");
		addModelField(DAY_SALARY_HOURS, "Day salary hours", "日计薪小时(h)");
	}
	
	@Override
	protected void addSearchFields() {
		super.addSearchField(convertPropertyToField(DEPTIDS));
	}
	
	@Override
	protected void addListFields() {
		addListField(convertPropertyToField(ACCTTERM, DEPARTMENT, MONTH_SALARY_DAYS, DAY_SALARY_HOURS));
	}
	
	@Override
	protected void addDetailFields() {
		addDetailField(convertPropertyToField(DEPTIDS, ACCTTERM, MONTH_SALARY_DAYS, DAY_SALARY_HOURS));
	}
	
	@Override
	protected void gatherExproperties() {
		exProperties.put(REQUIRED, new String[]{DEPTIDS, MONTH_SALARY_DAYS, DAY_SALARY_HOURS});
	}
	
	
	
	@Override
	protected void afterBuilderLayout() {
		DetailLayout layout = getDefaultDetailLayout();

		FlatSection fsResult =  layout.createFlatSection();
		fsResult.setNamePrefix("model");
		
		Model salaryItemView = getModel(SalaryEmployeeDefine.class);
		
		TabbedSection ts = elementService.createTabbedSection(getDefaultDetailLayout(), 1);
		List<FlatSection> tabPages = ts.getTabPages();
		
		List<Element> schedualScopeElements = elementService.createSectionElement(tabPages.get(0), salaryItemView.getDefaultListLayout().getSortChildren());
		GridSection gridSection = getMainGridSection(schedualScopeElements);
		gridSection.setReadOnly(false);
		gridSection.setTagName("datagrid");
		gridSection.setNamePrefix("employeeDefines");
		
		tabPages.get(0).setI18n("职员薪水定义");
	}
	
	
}
